package me.rocky.handler;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.support.WebExchangeBindException;

/**
 * @author Rocky
 * @version 1.0
 * @description
 * @email inaho00@foxmail.com
 * @createDate 2021/9/18 下午6:04
 * @log
 */
@ControllerAdvice
public class SystemExceptionHandler {

	@ExceptionHandler(WebExchangeBindException.class)
	public ResponseEntity<String> webExchangeBindExceptionHandler(WebExchangeBindException ex){
		return new ResponseEntity<>(ex.getFieldErrors()
				.stream()
				.map(e->e.getField()+ ":" + e.getDefaultMessage())
				.reduce("",(s1,s2)->s1+"\n"+s2), HttpStatus.NOT_FOUND);
	}
}
